package com.csmz.web.controller.enterprise;

import com.csmz.common.annotation.Log;
import com.csmz.common.core.controller.BaseController;
import com.csmz.common.core.domain.AjaxResult;
import com.csmz.common.core.page.TableDataInfo;
import com.csmz.common.enums.BusinessType;
import com.csmz.common.utils.poi.ExcelUtil;
import com.csmz.enterprise.domain.CsmzEnterprise;
import com.csmz.enterprise.service.ICsmzEnterpriseService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业信息Controller
 * 
 * @author TT
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/enterprise/enterpriseInfo")
public class CsmzEnterpriseController extends BaseController
{
    @Autowired
    private ICsmzEnterpriseService csmzEnterpriseService;

    /**
     * 查询企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsmzEnterprise csmzEnterprise)
    {
        startPage();
        List<CsmzEnterprise> list = csmzEnterpriseService.selectCsmzEnterpriseList(csmzEnterprise);
        return getDataTable(list);
    }

    /**
     * 查询我的企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:list')")
    @GetMapping("/myList")
    public TableDataInfo myList(CsmzEnterprise csmzEnterprise)
    {
        startPage();
        List<CsmzEnterprise> list = csmzEnterpriseService.selectCsmzEnterpriseMyList(csmzEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:export')")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsmzEnterprise csmzEnterprise)
    {
        List<CsmzEnterprise> list = csmzEnterpriseService.selectCsmzEnterpriseList(csmzEnterprise);
        ExcelUtil<CsmzEnterprise> util = new ExcelUtil<CsmzEnterprise>(CsmzEnterprise.class);
        util.exportExcel(response, list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:query')")
    @GetMapping(value = "/{enterpriseId}")
    public AjaxResult getInfo(@PathVariable("enterpriseId") Long enterpriseId)
    {
        return success(csmzEnterpriseService.selectCsmzEnterpriseByEnterpriseId(enterpriseId));
    }

    /**
     * 新增企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsmzEnterprise csmzEnterprise)
    {
        return toAjax(csmzEnterpriseService.insertCsmzEnterprise(csmzEnterprise));
    }

    /**
     * 新增我的企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping("/myAdd")
    public AjaxResult myAdd(@RequestBody CsmzEnterprise csmzEnterprise)
    {
        return toAjax(csmzEnterpriseService.insertMyCsmzEnterprise(csmzEnterprise));
    }

    /**
     * 修改企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsmzEnterprise csmzEnterprise)
    {
        return toAjax(csmzEnterpriseService.updateCsmzEnterprise(csmzEnterprise));
    }

    /**
     * 修改我的企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping("/myEdit")
    public AjaxResult myEdit(@RequestBody CsmzEnterprise csmzEnterprise)
    {
        return toAjax(csmzEnterpriseService.updateMyCsmzEnterprise(csmzEnterprise));
    }

    /**
     * 删除企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enterpriseIds}")
    public AjaxResult remove(@PathVariable Long[] enterpriseIds)
    {
        return toAjax(csmzEnterpriseService.deleteCsmzEnterpriseByEnterpriseIds(enterpriseIds));
    }

    /**
     *  获取认证结果
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseInfo:list')")
    @GetMapping("/certification")
    public AjaxResult getCertificationResult(){
        return success(csmzEnterpriseService.getCertificationResult(new CsmzEnterprise()));
    }

}
